3 // HigherOrderMessaging
5 // Created by Ofri Wolfus on 22/05/07.
6 // Copyright 2007 Ofri Wolfus. All rights reserved.
9 #import "DPDictionaryTests.h"
10 #import "DPCollectionEnumeration.h"
13 @implementation DPDictionaryTests
15 //=============================================
16 // NOTE: Tests are executed from the bottom up
17 //=============================================
19 - (BOOL)testCollectEach {
20 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"a", @"1",
23 NSSet *set = [NSSet setWithObjects:@"1", @"2", @"3", nil];
24 NSDictionary *result = [NSDictionary dictionaryWithObjectsAndKeys:@"a1", @"1",
28 return [[dict collect:MSG(stringByAppendingString:[set each])] isEqualToDictionary:result];
32 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"a", @"1",
35 NSDictionary *result = [NSDictionary dictionaryWithObjectsAndKeys:@"A", @"1",
39 return [[dict collect:MSG(capitalizedString)] isEqualToDictionary:result];
42 //=================================================================
43 // NOTE: All select/find + each combinations are meaningless
44 // for dictionaries as the order of objects in a dictionary
45 // can not be predicted.
46 //=================================================================
48 // There's no need to fully test rejectWhere: as it uses the
49 // same implementation of selectWhere:
50 - (BOOL)testRejectWhere {
51 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"a", @"1",
54 NSDictionary *result = [NSDictionary dictionaryWithObjectsAndKeys:@"b", @"2", @"c", @"3", nil];
56 return [[dict rejectWhere:MSG(hasPrefix:@"a"), nil] isEqualToDictionary:result];
59 - (BOOL)testSelectWhere_twoMessages {
60 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"a", @"1",
63 NSDictionary *result = [NSDictionary dictionaryWithObjectsAndKeys:@"a", @"1", @"abc", @"3", nil];
65 return [[dict selectWhere:MSG(capitalizedString), MSG(hasPrefix:@"A"), nil] isEqualToDictionary:result];
68 - (BOOL)testSelectWhere_oneMessage {
69 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"a", @"1", @"b", @"2",
71 NSDictionary *result = [NSDictionary dictionaryWithObjectsAndKeys:@"a", @"1", @"abc", @"3", nil];
73 return [[dict selectWhere:MSG(hasPrefix:@"a"), nil] isEqualToDictionary:result];
76 - (BOOL)testFindObjectWhere_twoMessages {
77 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"a", @"1", @"b", @"2",
79 return [[dict findObjectWhere:MSG(capitalizedString), MSG(hasPrefix:@"B"), nil] isEqualToString:@"b"];
82 - (BOOL)testFindObjectWhere_oneMessage {
83 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"a", @"1", @"b", @"2",
85 return [[dict findObjectWhere:MSG(hasPrefix:@"b"), nil] isEqualToString:@"b"];